import { AddressItem } from "@/api/address";
import { defineStore } from "pinia";
import { ref } from "vue";

const useAddressStore = defineStore(
  "address",
  () => {
    // 地址信息
    const seletedAddress = ref({} as AddressItem);

    // 修改地址信息数据的方法
    const changeSeletedAddress = (address: AddressItem) => {
      seletedAddress.value = address;
    };

    return { seletedAddress, changeSeletedAddress };
  },
  {
    persist: {
      storage: {
        setItem(key, value) {
          uni.setStorageSync(key, value);
        },
        getItem(key) {
          return uni.getStorageSync(key);
        },
      },
    },
  }
);

export default useAddressStore;
